<template>
  <div class="orderList w100p h100p flc oyhid">
    <div v-if="selectIdxs.length > 0" class="check" @click="checkClick">{{ checkLabel }}</div>
    <div class="flc pv6 ph16 bgWH">
      <div class="w100p flc">
        <div class="flr w100p">
          <div class="flc" :class="[queryParam.query1 !== 'commonSearch' ? 'w33p' : 'w100p']">
            <el-select v-model="queryParam.query1" placeholder="请选择" size="mini" class="w100p" @change="query1Change">
              <el-option label="通用" value="commonSearch" />
              <el-option v-for="item in typeList" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
            <el-select v-if="queryParam.query1 === 'purchaseInvoice' || queryParam.query1 === 'purchaseInvoiceReceive'" v-model="queryParam.data1" placeholder="请选择" size="mini" class="w100p">
              <el-option v-for="item in typeList1" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
            <el-input v-if="!(queryParam.query1 === 'purchaseInvoice' || queryParam.query1 === 'purchaseInvoiceReceive')" v-model="queryParam.data1" placeholder="请输入内容" size="mini" class="w100p" />
          </div>
          <div v-if="queryParam.query1 !== 'commonSearch'" class="flc w33p">
            <el-select v-model="queryParam.query2" placeholder="类型" size="mini" class="w100p" @change="query2Change">
              <el-option v-for="item in typeList" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
            <el-select v-if="queryParam.query2 === 'purchaseInvoice' || queryParam.query2 === 'purchaseInvoiceReceive'" v-model="queryParam.data2" placeholder="请选择" size="mini" class="w100p">
              <el-option v-for="item in typeList1" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
            <el-input v-if="!(queryParam.query2 === 'purchaseInvoice' || queryParam.query2 === 'purchaseInvoiceReceive')" v-model="queryParam.data2" placeholder="请输入内容" size="mini" class="w100p" />
          </div>
          <div v-if="queryParam.query1 !== 'commonSearch'" class="flc w33p">
            <el-select v-model="queryParam.query3" placeholder="类型" size="mini" class="w100p" @change="query3Change">
              <el-option v-for="item in typeList" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
            <el-select v-if="queryParam.query3 === 'purchaseInvoice' || queryParam.query3 === 'purchaseInvoiceReceive'" v-model="queryParam.data3" placeholder="请选择" size="mini" class="w100p">
              <el-option v-for="item in typeList1" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
            <el-input v-if="!(queryParam.query3 === 'purchaseInvoice' || queryParam.query3 === 'purchaseInvoiceReceive')" v-model="queryParam.data3" placeholder="请输入内容" size="mini" class="w100p" />
          </div>
        </div>
        <div class="flr w100p">
          <div class="flr wc60">
            <div class="l24 timeTile">时间</div>
            <div class="flb timeBox wc60">
              <div class="cGY2 l24 tc startTime" @click="startTimeClick('queryParam')">{{ queryParam.startTime }}</div>
              <div class="l24 to tc">至</div>
              <div class="cGY2 l24 tc endTime" @click="endTimeClick('queryParam')">{{ queryParam.endTime }}</div>
            </div>
          </div>
          <div class="fle w60">
            <van-button color="#409eff" block type="primary" size="mini" class="w60 br4" @click="searchData">查询</van-button>
          </div>
        </div>
      </div>
    </div>
    <div class="mt8 flr ph16 pv4 bgWH">
      <div class="w33p">
        <div class="l24">营收</div>
        <div class="cGY2 l24">{{ profitHandler(info.income) }}</div>
      </div>
      <div class="w33p">
        <div class="l24">成本</div>
        <div class="cGY2 l24">{{ profitHandler(info.cost) }}</div>
      </div>
      <div class="w33p">
        <div class="l24">利润</div>
        <div class="cGY2 l24">{{ profitHandler(info.profit) }}</div>
      </div>
    </div>
    <!-- <div class="contentList" :class="[selectIdxs.length === 0 ? '' : 'hc247']"> -->
    <van-list v-model="loading" class="contentList oyauto oxnone" :class="[selectIdxs.length === 0 ? '' : 'hc247']" :finished="finished" finished-text="没有更多了" @load="queryData">
      <div v-for="(item, index) in orderList" :key="index" :class="[index === 0 ? '' : 'mt8']" class="bgWH flr pv6 w100p contentBox">
        <div class="flc contentItem">
          <div class="rotate" @click="orderClick(item)">{{ getPingyin(item.companySaleName) }}</div>
          <div class="flb first" @click="orderClick(item)">
            <div class="f12 l20 cGY2 w60">{{ item.dateInput | dateShort }}</div>
            <div class="f12 l20 cGY2 ellipsis w230">{{ item.productSupplierName }}</div>
            <div class="fle w150">
              <div class="f12 l20 cGY2">{{ item.invoiceNo }}</div>
              <van-icon name="checked" class="cGY2 f12 l19" :class="[item.purchaseInvoiceReceive === '1' ? 'cGR' : 'cGY2']" />
            </div>
          </div>
          <div class="flr">
            <div class="checkbox flca">
              <van-checkbox v-model="item.checked" />
            </div>
            <div class="flr mt4 nameprice" @click="orderClick(item)">
              <div class="flc wc150">
                <div class="f12 l18 w100p ellipsis">{{ item.productBrandName }}</div>
                <div class="f12 l18 w100p ellipsis">{{ item.productBrandArticleNoName }}</div>
                <div class="f12 l18 w100p ellipsis">{{ item.productBrandArticleNo }}</div>
              </div>
              <div class="flb priceBox" @click="orderClick(item)">
                <van-icon name="gold-coin" class="cGY2 f12 l54" :class="[item.purchaseInvoice === '1' ? 'cGR' : 'cGY2']" />
                <div class="ph4 l54 cGR1">进</div>
                <div class="flc w47">
                  <div class="l27 ofxhd">{{ Math.floor(item.purchaseSinglePrice) }}</div>
                  <div class="l27 ofxhd">{{ Math.floor(item.purchaseTotalPrice) }}</div>
                </div>
                <div class="ph4 l54 cYL">出</div>
                <div class="flc w47">
                  <div class="l27 ofxhd">{{ Math.floor(item.customerSinglePrice) }}</div>
                  <div class="l27 ofxhd">{{ Math.floor(item.customerTotalPrice) }}</div>
                </div>
              </div>
            </div>
          </div>
          <div class="flb mt4 bt" @click="orderClick(item)">
            <div class="f12 l20 cGY2 w110 ellipsis">{{ item.productSpecificationName }}</div>
            <div class="f12 l20 cGY2 w40">{{ Math.floor(item.qty) }}{{ item.unit }}</div>
            <div class="f12 l20 cGY2 wc216 ellipsis">{{ item.customerName }}</div>
            <div class="f12 l20 cGY2 w36">{{ item.customerPurchaserName }}</div>
          </div>
        </div>
      </div>
    </van-list>
    <!-- </div> -->
    <div v-if="selectIdxs.length > 0" class="flc w100p footer ph16 pv8 bgWH">
      <div class="flr">
        <span class="f12 l18">已选</span>
        <span class="cYE mr2 ml2 f12 l18">{{ selectIdxs.length }}</span>
        <span class="f12 l18">个订单</span>
      </div>
      <div class="flb w100p mt3">
        <van-button color="#ff0000" class="w30p br4" size="mini" :disabled="!isAdmin" @click="delOrders">删除订单</van-button>
        <van-button color="#FF8D1A" class="w30p br4" size="mini" @click="exportList">生成清单</van-button>
        <van-button color="#36B4C8" class="w30p br4" size="mini" @click="showPurchaseInvoiceReceiveBtn">标记回款</van-button>
      </div>
      <div class="flb w100p mt6">
        <van-button color="#7232dd" class="w30p br4" size="mini" @click="showInvoiceNoBtn">输入发票号</van-button>
        <van-button color="#FF8D1A" class="w30p br4" size="mini" @click="exportOutOrder">生成出库单</van-button>
        <van-button color="#36B4C8" class="w30p br4" size="mini" @click="showPurchaseInvoiceBtn">标记进项票</van-button>
      </div>
    </div>
    <van-popup v-model="startTimeShow" round position="bottom">
      <van-datetime-picker v-model="startDate" type="date" title="选择年月日" :min-date="minDate" :max-date="maxDate" @cancel="startTimeShow = false" @confirm="startDateTime" />
    </van-popup>
    <van-popup v-model="endTimeShow" round position="bottom">
      <van-datetime-picker v-model="endDate" type="date" title="选择年月日" :min-date="minDate" :max-date="maxDate" @cancel="endTimeShow = false" @confirm="endDateTime" />
    </van-popup>
    <van-popup v-model="showInvoiceNo" round position="bottom">
      <van-form class="oyauto w100p" @submit="updateInvoiceNo">
        <van-field v-model="invoiceNo" class="mt10" name="发票号" label="发票号" placeholder="发票号" :rules="[{ required: true, message: '请填写发票号' }]" />
        <div style="margin: 16px;">
          <van-button color="#409eff" round block type="primary" native-type="submit">更新</van-button>
        </div>
      </van-form>
    </van-popup>
    <van-popup v-model="showPurchaseInvoice" round position="bottom">
      <van-form class="oyauto w100p" @submit="updatePurchaseInvoice">
        <van-cell>
          <template #title>
            <div class="f12 l20 cGY2">是否进项票</div>
          </template>
        </van-cell>
        <van-radio-group v-model="purchaseInvoice">
          <van-cell-group>
            <van-cell title="已进项票" clickable @click="purchaseInvoice = '是'">
              <template #right-icon>
                <van-radio name="是" />
              </template>
            </van-cell>
            <van-cell title="未进项票" clickable @click="purchaseInvoice = '否'">
              <template #right-icon>
                <van-radio name="否" />
              </template>
            </van-cell>
          </van-cell-group>
        </van-radio-group>
        <div style="margin: 16px;">
          <van-button color="#409eff" round block type="primary" native-type="submit">更新</van-button>
        </div>
      </van-form>
    </van-popup>
    <van-popup v-model="showPurchaseInvoiceReceive" round position="bottom">
      <van-form class="oyauto w100p" @submit="updatePurchaseInvoiceReceive">
        <van-cell>
          <template #title>
            <div class="f12 l20 cGY2">是否回款</div>
          </template>
        </van-cell>
        <van-radio-group v-model="purchaseInvoiceReceive">
          <van-cell-group>
            <van-cell title="已回款" clickable @click="purchaseInvoiceReceive = '是'">
              <template #right-icon>
                <van-radio name="是" />
              </template>
            </van-cell>
            <van-cell title="未回款" clickable @click="purchaseInvoiceReceive = '否'">
              <template #right-icon>
                <van-radio name="否" />
              </template>
            </van-cell>
          </van-cell-group>
        </van-radio-group>
        <div style="margin: 16px;">
          <van-button color="#409eff" round block type="primary" native-type="submit">更新</van-button>
        </div>
      </van-form>
    </van-popup>
    <van-popup v-model="showOrderInfo" round position="bottom">
      <van-form class="w100p mt16" @submit="showOrderInfo = false">
        <div class="form oyauto w100p">
          <van-field v-model="orderInfo.companyName" readonly label="公司名称" />
          <van-field v-model="orderInfo.companySaleName" readonly label="业务员" />
          <van-field v-model="orderInfo.dateInput" readonly label="日期" />
          <van-field v-model="orderInfo.customerName" readonly label="客户单位" />
          <van-field v-model="orderInfo.customerPurchaserName" readonly label="采购人" />
          <van-field v-model="orderInfo.customerPurchaserPhone" readonly label="电话" />
          <van-field v-model="orderInfo.customerAddress" readonly label="地址" />
          <van-field v-model="orderInfo.productBrandName" readonly label="品牌" />
          <van-field v-model="orderInfo.productBrandArticleNo" readonly label="货号" />
          <van-field v-model="orderInfo.productBrandArticleNoName" readonly label="单品名称" />
          <van-field v-model="orderInfo.qty" readonly label="数量" />
          <van-field v-model="orderInfo.unit" readonly label="计量单位" />
          <van-field v-model="orderInfo.purchaseSinglePrice" readonly label="拿货单价" />
          <van-field v-model="orderInfo.customerSinglePrice" readonly label="客户单价" />
          <van-field v-model="orderInfo.productSupplierName" readonly label="供应商" />
          <van-field v-model="orderInfo.purchaseInvoice" readonly label="进项票" />
          <van-field v-model="orderInfo.invoiceNo" readonly label="发票号" />
          <van-field v-model="orderInfo.purchaseInvoiceReceive" readonly label="是否回款" />
          <van-field v-model="orderInfo.remark" readonly label="备注" />
        </div>
        <div style="margin: 16px;">
          <van-button color="#409eff" round block type="primary" native-type="submit">确定</van-button>
        </div>
      </van-form>
    </van-popup>
    <van-popup v-model="showBank" round position="bottom">
      <van-form class="w100p mt16" @submit="bankSelected">
        <van-radio-group v-model="selectBankIdx">
          <van-cell-group>
            <van-cell :title="bankInfo.bank1" :label="bankInfo.address1" clickable @click="selectBankIdx = '1'">
              <template #right-icon>
                <van-radio name="1" />
              </template>
            </van-cell>
            <van-cell :title="bankInfo.bank2" :label="bankInfo.address2" clickable @click="selectBankIdx = '2'">
              <template #right-icon>
                <van-radio name="2" />
              </template>
            </van-cell>
          </van-cell-group>
        </van-radio-group>
        <div style="margin: 16px;">
          <van-button color="#409eff" round block type="primary" native-type="submit">确定</van-button>
        </div>
      </van-form>
    </van-popup>
  </div>
</template>
<script>
import pinyin from 'js-pinyin';
import { getSaleOrderList, getStatistics, deleteSaleOrder, exportSaleOrderList } from '../utils/api';
import moment from 'moment';
export default {
  filters: {
    dateShort(val) {
      if (!val) {
        return '';
      }
      return val.substring(2);
    }
  },
  data() {
    return {
      loading: false,
      finished: false,
      checkList: [],
      checkLabel: '选',
      isAdmin: false,
      showInvoiceNo: false,
      showPurchaseInvoice: false,
      showPurchaseInvoiceReceive: false,
      invoiceNo: undefined,
      purchaseInvoice: undefined,
      purchaseInvoiceReceive: undefined,
      showFooter: false,
      startTimeShow: false,
      endTimeShow: false,
      startDate: undefined,
      endDate: undefined,
      info: { income: '', cost: '', profit: '' },
      minDate: new Date(2020, 0, 1),
      maxDate: new Date(2030, 12, 31),
      orderInfo: {},
      showOrderInfo: false,
      queryStatisticsParam: {
        startTime: moment()
          .startOf('year')
          .format('YYYY-MM-DD'),
        endTime: moment().format('YYYY-MM-DD')
      },
      dateType: '',
      queryParam: {
        query1: 'commonSearch',
        data1: '',
        query2: '',
        data2: '',
        query3: '',
        data3: '',
        startTime: moment()
          .startOf('year')
          .format('YYYY-MM-DD'),
        endTime: moment().format('YYYY-MM-DD')
      },
      searchParam: {},
      orderList: [],
      selectIdxs: [],
      bankInfo: [],
      bankAllInfo: {},
      showBank: false,
      pageSize: 20,
      pageNum: 1,
      selectBankIdx: -1,
      typeList: [
        { value: 'companyName', label: '公司' },
        { value: 'companySaleName', label: '业务员' },
        { value: 'customerName', label: '客户单位' },
        { value: 'customerPurchaserName', label: '客户采购人' },
        { value: 'productBrandName', label: '品牌' },
        { value: 'productBrandArticleNo', label: '货号' },
        { value: 'productBrandArticleNoName', label: '单品名称' },
        { value: 'productSpecificationName', label: '规格' },
        { value: 'unit', label: '计量单位' },
        { value: 'productSupplierName', label: '供应商' },
        { value: 'purchaseInvoice', label: '进项票' },
        { value: 'invoiceNo', label: '发票' },
        { value: 'purchaseInvoiceReceive', label: '回款' },
        { value: 'remark', label: '备注' }
      ],
      typeList1: [
        { value: '1', label: '是' },
        { value: '2', label: '否' }
      ]
    };
  },
  watch: {
    orderList: {
      handler() {
        this.checkboxChange();
      },
      immediate: true,
      deep: true
    }
  },
  mounted() {
    if (this.$route.query.type === 'true') {
      this.isAdmin = true;
    }
  },
  methods: {
    //查询列表数据
    async queryData(type = true) {
      let param = {
        pageSize: this.pageSize,
        pageNum: this.pageNum++,
        companyName: '', //公司名称
        companySaleName: '', //公司销售
        startTime: this.queryParam.startTime,
        endTime: this.queryParam.endTime,
        customerName: '', //客户单位
        customerPurchaserName: '', //采购人
        productBrandName: '', //品牌
        productBrandArticleNo: '', //货号
        productBrandArticleNoName: '', //单品名称
        productSpecificationName: '', //规格
        unit: '', //计量单位
        productSupplierName: '', //供应商
        purchaseInvoice: '', //进项票
        invoiceNo: '', //发票号
        purchaseInvoiceReceive: '', //是否回款
        remark: '' //备注
      };
      if (this.queryParam.query1 === 'commonSearch') {
        param.commonSearch = this.queryParam.data1;
      } else {
        param[this.queryParam.query1] = this.queryParam.data1;
        if (this.queryParam.query2) {
          param[this.queryParam.query2] = this.queryParam.data2;
        }
        if (this.queryParam.query3) {
          param[this.queryParam.query3] = this.queryParam.data3;
        }
      }
      this.searchParam = param;
      let res = await getSaleOrderList(param);
      res.data.map(item => {
        item.checked = false;
      });
      this.orderList = [...this.orderList, ...res.data];
      this.loading = false;
      if (res.data.length < 20) {
        this.finished = true;
      }
      //以下是修改统计区域的值
      if (type) {
        //   let purchaseTotalPrice = 0;
        //   let customerTotalPrice = 0;
        //   res.data.forEach(el => {
        //     purchaseTotalPrice += Number(el.purchaseTotalPrice);
        //     customerTotalPrice += Number(el.customerTotalPrice);
        //   });
        //   this.info.income = customerTotalPrice;
        //   this.info.cost = purchaseTotalPrice;
        //   this.info.profit = customerTotalPrice - purchaseTotalPrice;
        this.getStatisticsData();
      }
    },
    searchData() {
      this.pageNum = 1;
      this.orderList = [];
      this.queryData(true);
      this.getStatisticsData();
    },
    async getStatisticsData() {
      let res = await getStatistics({ startTime: this.queryParam.startTime, endTime: this.queryParam.endTime });
      this.info = { ...res.data };
    },
    //人名转拼音
    getPingyin(name) {
      return pinyin.getCamelChars(name);
    },
    //日期1点击
    startTimeClick(type) {
      this.dateType = type;
      this.startDate = new Date(moment().year(), moment().month(), moment().format('DD'));
      this.startTimeShow = true;
    },
    //日期2点击
    endTimeClick(type) {
      this.dateType = type;
      this.endDate = new Date(moment().year(), moment().month(), moment().format('DD'));
      this.endTimeShow = true;
    },
    //日期框1确认
    startDateTime(time) {
      this[this.dateType].startTime = moment(time).format('YYYY-MM-DD');
      this.startTimeShow = false;
    },
    //日期框2确认
    endDateTime(time) {
      this[this.dateType].endTime = moment(time).format('YYYY-MM-DD');
      this.endTimeShow = false;
    },
    //删除多个订单
    async delOrders(item) {
      await this.$async.confirm({ message: `确认要删除${this.selectIdxs.length}条订单信息吗？` });
      let idxs = [];
      this.selectIdxs.forEach(el => {
        idxs.push(this.orderList[el].id);
      });
      await deleteSaleOrder({ saleOrderIds: idxs });
      this.$toast({ type: 'success', message: '删除成功' });
      this.queryData();
    },
    //点击查看订单详情
    orderClick(item) {
      this.orderInfo = { ...item, purchaseInvoice: item.purchaseInvoice === '1' ? '是' : '否', purchaseInvoiceReceive: item.purchaseInvoiceReceive === '1' ? '是' : '否' };
      this.showOrderInfo = true;
    },
    //处理选中
    checkboxChange() {
      this.selectIdxs = [];
      this.orderList.forEach((item, idx) => {
        if (item.checked) {
          this.selectIdxs.push(idx);
        }
      });
    },
    //全选反选
    checkClick() {
      this.checkLabel = this.checkLabel === '选' ? '反' : '选';
      this.selectIdxs = [];
      this.orderList.forEach((item, idx) => {
        if (this.checkLabel === '反') {
          item.checked = true;
          this.selectIdxs.push(idx);
        } else {
          item.checked = false;
        }
      });
    },
    //导出清单
    exportList() {
      let param = JSON.parse(JSON.stringify(this.searchParam));
      param = { ...param, pageNum: 1, pageSize: 500 };
      uni.postMessage({ data: ['list', param, this.selectIdxs] }); //eslint-disable-line
    },
    //导出出库单
    async exportOutOrder() {
      let arr = []; //所选中的订单
      this.selectIdxs.forEach(el => {
        arr.push(this.orderList[el]);
      });
      if (arr.length > 1) {
        if (!this.checkDuplicate(arr, 'customerName')) {
          this.$toast('请选择相同的客户');
          return;
        } else if (!this.checkDuplicate(arr, 'companyName')) {
          this.$toast('请选择相同的供销公司');
          return;
        }
      }
      let res = await exportSaleOrderList({ saleOrderIds: [this.orderList[this.selectIdxs[0]].id] });
      this.bankAllInfo = res.data[0];
      if (res.data[0].address !== '//') {
        this.bankInfo = {
          bank1: res.data[0].bank.split('//')[0],
          address1: res.data[0].bank.split('//')[1],
          bank2: res.data[0].address.split('//')[0],
          address2: res.data[0].address.split('//')[1],
          taxNo: res.data[0].taxNo
        };
        this.showBank = true;
      } else {
        let info = {
          bank: res.data[0].bank.split('//')[0],
          address: res.data[0].bank.split('//')[1],
          companySalePhone: res.data[0].companySalePhone,
          taxNo: res.data[0].taxNo
        };
        let param = JSON.parse(JSON.stringify(this.searchParam));
        param = { ...param, pageNum: 1, pageSize: 500 };
        uni.postMessage({ data: ['out', param, this.selectIdxs, info] }); //eslint-disable-line
      }
    },
    //选择开户行
    bankSelected() {
      if (this.selectBankIdx !== -1) {
        let info = {
          bank: this.bankInfo[`bank${this.selectBankIdx}`],
          address: this.bankInfo[`address${this.selectBankIdx}`],
          companySalePhone: this.bankAllInfo.companySalePhone,
          taxNo: this.bankAllInfo.taxNo
        };
         let param = JSON.parse(JSON.stringify(this.searchParam));
        param = { ...param, pageNum: 1, pageSize: 500 };
        uni.postMessage({ data: ['out', param, this.selectIdxs, info] }); //eslint-disable-line
        this.showBank = false;
        this.selectBankIdx = -1;
      }
    },
    //检测重复属性
    checkDuplicate(array, key) {
      let values = new Set();
      for (let i = 0; i < array.length; i++) {
        let value = array[i][key];
        if (values.has(value)) {
          return true;
        }
        values.add(value);
      }
      return false;
    },
    //展示发票号弹框
    async showInvoiceNoBtn() {
      this.showInvoiceNo = true;
    },
    //展示进票项弹框
    showPurchaseInvoiceBtn() {
      this.showPurchaseInvoice = true;
    },
    //展示回款弹框
    showPurchaseInvoiceReceiveBtn() {
      this.showPurchaseInvoiceReceive = true;
    },
    //更新发票号
    async updateInvoiceNo() {
      let axiosList = [];
      this.selectIdxs.forEach(el => {
        axiosList.push({ url: '/business/saleOrder/update', data: { ...this.orderList[el], invoiceNo: this.invoiceNo, saleOrderIds: [this.orderList[el].id] } });
      });
      await this.$axiosAll(axiosList);
      this.$toast.success('发票号更新成功');
      this.queryData();
      this.showInvoiceNo = false;
    },
    //更新进票项
    async updatePurchaseInvoice() {
      if (this.purchaseInvoice === '是' || this.purchaseInvoice === '否') {
        let axiosList = [];
        this.selectIdxs.forEach(el => {
          axiosList.push({ url: '/business/saleOrder/update', data: { ...this.orderList[el], purchaseInvoice: this.purchaseInvoice === '是' ? '1' : '2', saleOrderIds: [this.orderList[el].id] } });
        });
        await this.$axiosAll(axiosList);
        this.$toast.success('进项票更新成功');
        this.queryData();
        this.purchaseInvoice = undefined;
        this.showPurchaseInvoice = false;
      } else {
        this.$toast.fail('请填写是或者否');
      }
    },
    //更新回款
    async updatePurchaseInvoiceReceive() {
      if (this.purchaseInvoiceReceive === '是' || this.purchaseInvoiceReceive === '否') {
        let axiosList = [];
        this.selectIdxs.forEach(el => {
          axiosList.push({
            url: '/business/saleOrder/update',
            data: { ...this.orderList[el], purchaseInvoiceReceive: this.purchaseInvoiceReceive === '是' ? '1' : '2', saleOrderIds: [this.orderList[el].id] }
          });
        });
        await this.$axiosAll(axiosList);
        this.$toast.success('是否回款更新成功');
        this.queryData();
        this.purchaseInvoiceReceive = undefined;
        this.showPurchaseInvoiceReceive = false;
      } else {
        this.$toast.fail('请选择是或者否');
      }
    },
    query1Change() {
      this.queryParam.data1 = undefined;
      if (this.queryParam.query1 === 'commonSearch') {
        this.queryParam.query2 = undefined;
        this.queryParam.query3 = undefined;
        this.queryParam.data2 = undefined;
        this.queryParam.data3 = undefined;
      }
    },
    query2Change() {
      this.queryParam.data2 = undefined;
    },
    query3Change() {
      this.queryParam.data3 = undefined;
    },
    //处理精度
    profitHandler(num) {
      let data = Math.round(num * 100);
      return (data / 100).toFixed(2);
    }
  }
};
</script>
<style lang="less" scoped>
.orderList {
  background: #f2f5f8;
  position: relative;
  .check {
    position: fixed;
    left: 0;
    top: 269px;
    width: 24px;
    padding-left: 6px;
    background: #409eff;
    line-height: 28px;
    font-size: 12px;
    color: white;
    border-top-right-radius: 14px;
    border-bottom-right-radius: 14px;
    z-index: 10;
  }
  .ft111 {
    top: 111px;
  }
  .ft233 {
    top: 233px;
  }
  .dateBox {
    border-bottom: 1px solid #eee;
    box-sizing: border-box;
    height: 40px;
  }
  .timeTile {
    width: 60px;
  }
  .timeBox {
    .startTime,
    .endTime {
      width: calc((100% - 30px) / 2);
    }
    .to {
      width: 30px;
    }
  }
  .form {
    height: 60vh;
    /deep/ .van-field__control:read-only {
      color: #999 !important;
    }
    /deep/ .van-field__label {
      color: #323232 !important;
    }
  }
  .wc216 {
    width: calc(100% - 216px);
  }
  .w230 {
    width: calc(100% - 230px);
  }
  .first {
    padding-left: 30px;
    box-sizing: border-box;
    width: calc(100% - 14px);
  }
  .contentList {
    height: calc(100% - 156px);
    padding: 8px 0 0 0;
    box-sizing: border-box;
    .list {
      height: 100%;
      overflow-y: auto;
      overflow-x: hidden;
    }
  }
  .bt {
    padding-left: 30px;
    box-sizing: border-box;
  }
  .hc247 {
    height: calc(100% - 247px);
  }
  .wc150 {
    width: calc(100% - 150px);
  }
  .priceBox {
    width: 150px;
  }
  /deep/ .el-input.is-disabled .el-input__inner {
    background: white;
  }
  .contentBox {
    position: relative;
    .contentItem {
      width: calc(100% - 0px);
      padding: 0 16px;
      box-sizing: border-box;
      .checkbox {
        padding-right: 10px;
        box-sizing: border-box;
      }
      .nameprice {
        width: calc(100% - 30px);
      }
    }
  }
  .rotate {
    -moz-transform: rotate(45deg);
    -webkit-transform: rotate(45deg);
    display: block;
    position: absolute;
    right: -4px;
    top: 14px;
    width: 40px;
    height: 12px;
    font-size: 12px;
    color: #969799;
    line-height: 12px;
    text-align: center;
    filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
  }
  .footer {
    border-top: 1px solid #eee;
    box-sizing: border-box;
    height: 91px;
    position: absolute;
    right: 0;
    bottom: 0;
    width: 100%;
  }
}
</style>
